﻿using System;

namespace Lesson18_练习题
{
    //创建一个图形类 有求面积和周长两个方法
    //创建矩形类、正方形类、圆形类继承图形类
    abstract class Figure
    {
        public abstract float GetArea();
        public abstract float GetPerimeter();
    }
    class Rectangle : Figure
    {
        private float l;
        private float w;
        public Rectangle(float l, float w)
        {
            this.l = l;
            this.w = w;
        }
        public override float GetArea()
        {
            return l * w;
        }

        public override float GetPerimeter()
        {
            return (l * 2) + (w * 2);
        }
    }
    class Square : Figure
    {
        private float a;
        public Square(float a)
        {
            this.a = a;
        }
        public override float GetArea()
        {
            return a * a;
        }

        public override float GetPerimeter()
        {
            return 4 * a;
        }
    }
    class Circle : Figure
    {
        private float r;
        private const float PI = 3.14f;
        public Circle(float r)
        {
            this.r = r;
        }

        public override float GetArea()
        {
            return PI * r * r;
        }

        public override float GetPerimeter()
        {
            return 2 * PI * r;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Figure r = new Rectangle(2, 3);
            Console.WriteLine(r.GetArea());
            Console.WriteLine(r.GetPerimeter());
            Figure s = new Square(4);
            Console.WriteLine(s.GetArea());
            Console.WriteLine(s.GetPerimeter());
            Figure c = new Circle(5);
            Console.WriteLine(c.GetArea());
            Console.WriteLine(c.GetPerimeter());

        }
    }
}